<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>WebCópias - Manutenção de Serviços</title>
	<link rel="shortcut icon" href="../assets/image/favicon.ico" />
	<link rel="stylesheet" href="../assets/css/styleService.css" />
	<script type="text/javascript">
		function clearFields(fields){
			var fieldsSplit = fields.split(",");
			
			for(var i in fieldsSplit){
				document.getElementById(fieldsSplit[i]).value = "";
			}
		}
	</script>
</h:head>
<body>
	<p:growl id="resultMessage" showDetail="true" life="4000" />
	<p:layout fullPage="true" styleClass="container">
		<p:layoutUnit position="north" size="95" resizable="false" closable="false"	collapsible="false" styleClass="header">
			<ui:include src="/form/header.xhtml"></ui:include>
		</p:layoutUnit>
		<p:layoutUnit position="west" size="200" header="Navegação" collapsible="true"	styleClass="menu" style="padding:0 !important;">
			<ui:include src="/form/menu.xhtml"></ui:include>
		</p:layoutUnit>
		<p:layoutUnit position="center" header="Manutenção de Serviços" styleClass="content">
			<h:form id="datatableForm">
				<p:dataTable id="serviceDatatable" emptyMessage="Nenhum serviço encontrado" var="services" value="#{service.listServices}" widgetVar="servicesList" styleClass="datatable-service">
					<f:facet name="header">
						<p:commandButton id="btAddService" styleClass="addServiceButton" onclick="clearFields('addDescription,addCost')" actionListener="#{service.prepareCreateService}" oncomplete="addNewService.show()" value="Adicionar Serviço" icon="ui-icon-circle-plus" title="Adicionar Serviço" ></p:commandButton>
					</f:facet>  
			        <p:column headerText="Descrição" style="width:30%" styleClass="column-datatable">  
			            <h:outputText value="#{services.serviceName}" styleClass="value-datatable"/>  
			        </p:column>  
			  
			        <p:column headerText="Valor" style="width:10%" styleClass="column-datatable">  
			            <h:outputText value="#{services.serviceCost}" styleClass="value-datatable"/>  
			        </p:column>  
			  
			        <p:column style="width:5%; text-align:center !important;" styleClass="column-datatable">  
		                <p:commandButton id="btEditService" oncomplete="editService.show()" icon="ui-icon-pencil" update=":formEditService:panelEditService" title="Editar">  
			                <f:setPropertyActionListener value="#{services}" target="#{service.selectedService}" styleClass="value-datatable"/>  
		           		</p:commandButton>  
	                	<p:commandButton id="btViewService" oncomplete="viewService.show()" icon="ui-icon-search" update=":formViewService:panelViewService" title="Visualisar"> 
		                	<f:setPropertyActionListener value="#{services}" target="#{service.selectedService}" styleClass="value-datatable"/>  
		            	</p:commandButton>  
		                <p:commandButton id="btDeleteService" oncomplete="confirmationDeleteService.show()" icon="ui-icon-trash" title="Remover">  
			                <f:setPropertyActionListener value="#{services}" target="#{service.selectedService}" styleClass="value-datatable"/>  
			            </p:commandButton>  
			        </p:column>  
			  
			    </p:dataTable>
			</h:form>
		</p:layoutUnit>
	</p:layout>
	
	<p:dialog header="Editar Serviço" widgetVar="editService" resizable="false" modal="true" showEffect="fade" width="600">
		<h:form prependId="false" id="formEditService">
			<h:panelGrid id="panelEditService" columns="2" style="margin-bottom:30px">
				<h:outputLabel for="editDescription" value="Descrição:" />
				<p:inputText value="#{service.selectedService.serviceName}" id="editDescription" size="30"/>

				<h:outputLabel for="editCost" value="Preço por cópia" />
				<p:inputText value="#{service.selectedService.serviceCost}" id="editCost" size="10"/>
				
				<f:facet name="footer">
					<p:separator/>
					<p:commandButton actionListener="#{service.updateService}" oncomplete="editService.hide()" 
					update=":datatableForm:serviceDatatable :resultMessage" value="Comfirmar" />
					<p:commandButton oncomplete="editService.hide()" value="Fechar" />
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
	
	<p:dialog header="Adicionar Serviço" widgetVar="addNewService" resizable="false" modal="true" showEffect="fade" width="600">
		<h:form prependId="false" id="formAddService">
			<h:panelGrid id="panelAddService" columns="2" style="margin-bottom:10px">
				<h:outputLabel for="addDescription" value="Descrição:" />
				<p:inputText value="#{service.selectedService.serviceName}" id="addDescription" size="30"/>

				<h:outputLabel for="addCost" value="Preço por cópia:" />
				<p:inputText value="#{service.selectedService.serviceCost}" id="addCost" size="10"/>

				<f:facet name="footer">
					<p:separator/>
					<p:commandButton actionListener="#{service.createNewService}" oncomplete="addNewService.hide()" 
					update=":datatableForm:serviceDatatable :resultMessage" value="Comfirmar" />
				
					<p:commandButton oncomplete="addNewService.hide()" value="Fechar" />
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
	
	<p:dialog header="Informações do Serviço" widgetVar="viewService" resizable="false" modal="true" showEffect="fade" width="600">
		<h:form prependId="false" id="formViewService">
			<h:panelGrid id="panelViewService" columns="2" style="margin-bottom:10px">
				<h:outputLabel for="viewDescription" value="Description:" />
				<p:inputText value="#{service.selectedService.serviceName}" id="viewDescription" readonly="true" size="30"/>

				<h:outputLabel for="viewCost" value="Nome:" />
				<p:inputText value="#{service.selectedService.serviceCost}" id="viewCost" readonly="true" size="10"/>
				
				<f:facet name="footer">
					<p:separator/>
					<p:commandButton oncomplete="viewService.hide()" value="Fechar" />
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
	
	<h:form>  
	    <p:confirmDialog id="confirmDeleteService" message="Deseja remover este serviço?" header="Remover serviço" severity="alert" widgetVar="confirmationDeleteService">  
	        <p:commandButton id="confirmDelete" value="Sim" onclick="confirmationDeleteService.hide()" update=":datatableForm:serviceDatatable :resultMessage" actionListener="#{service.deleteService}" />  
	        <p:commandButton id="decline" value="Não" onclick="confirmationDeleteService.hide()" type="button" />   
	    </p:confirmDialog>  
	</h:form>
	
	<p:dialog header="Alterar Conta" widgetVar="updateAccount" resizable="false" modal="true" showEffect="slide" width="500">
		<h:form prependId="false">
			<h:panelGrid id="infosLivro" columns="2" style="margin-bottom:10px">
				<h:outputLabel for="updateRegistration" value="Matrícula:" />
				<p:inputText value="#{user.loggedUser.registration}" id="updateRegistration" disabled="true" />

				<h:outputLabel for="updateName" value="Nome:" />
				<p:inputText value="#{user.loggedUser.name}" id="updateName" />

				<h:outputLabel for="updatePassword" value="Senha:" />
				<h:inputSecret value="#{user.loggedUser.password}" id="updatePassword" styleClass="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-state-hover" />

				<h:outputLabel for="updateEmail" value="E-mail:" />
				<p:inputText value="#{user.loggedUser.email}" id="updateEmail" required="false" />

				<h:outputLabel for="updatePhoto" value="Foto:" />
				<p:inputText value="#{user.loggedUser.photo}" id="updatePhoto" required="false" />
				
				<f:facet name="footer">
					<p:separator/>
					<p:commandButton oncomplete="updateAccount.hide()" actionListener="#{user.selfUpdateUser}" update=":resultMessage" value="Salvar"/>
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
</body>
</html>